<template>
	<view class="page" :style="'height:' + height + 'rpx'">
		<view class="box">
			<view class="title">
				<text class="iconfont icon-a-ziyuan103"></text>
				<text style="margin-left: 10rpx; margin-right: 10rpx;font-weight: 700; font-size: 38rpx;">{{memberData.mainerName}}</text>
				<text>邀请你</text>
			</view>
			<view class="excel_box" >
				加入{{memberData.orgName}}无课时间一览表.xls
			</view>
			<button style="margin-top: 120rpx;background-color:#23b8ff ;color: #fff;" @click="agree()">同意</button>
			<button style="color: #23b8ff;" @click="reject()">拒绝</button>
		</view>
		
	</view>
</template>

<script>
	export default {
		onLoad(option) {
			uni.showLoading({
				title: '加载中..',
				// mask: true
			})
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					let pxToRpxScale = 750 / res.windowWidth;
					that.height = res.windowHeight * pxToRpxScale;
				}
			})
			if (option.data) {
				// console.log(JSON.parse(option.data));
				this.memberData = JSON.parse(option.data)
				// console.log(this.memberData )
				// uni.hideLoading()
			}
			this.header.Authority = uni.getStorageSync('Authority');
			uni.hideLoading()
		},
		data() {
			return {
				header: {
					Authority: ''
				},
				height: 0,
				memberData: null,
				hasClickAgree: false,
				hasClickReject: false
			}
		},
		methods: {
			async agree() {
				console.log('执行')
				if (!this.hasClickAgree) {
					this.hasClickAgree = true
					console.log('执行请求')
					let res = await getApp().UniRequest("/timeoff/authority/agreeInvited?xlsId=" + this.memberData.xlsId, "POST", "",
						this.header);
						console.log('同意',res)
						if (res.code === 20000) {
							
							uni.showToast({
							    title: '已加入',
								icon: 'success',
							    duration: 2000,
								success() {
									//返回那个页面
					
									setTimeout(() => {
										uni.navigateBack({
										    delta: 1
										});
									},600)
					
								}
							});
					
						} else {
							uni.showToast({
							    title: '请稍后重试',
								icon: 'success',
							    duration: 2000,
								success() {
									//返回那个页面
									setTimeout(() => {
										uni.navigateBack({
										    delta: 1
										});
									},600)
								
								}
							});
						}
				}

			},
			async reject() {
				console.log('执行')
				if (!this.hasClickReject) {
					this.hasClickReject = true
					console.log('执行拒绝')
					let that = this;
					uni.showModal({
					    title: '提示',
					    content: '确定拒绝加入?',
					    success: async function (res) {
					        if (res.confirm) {
					           let res = await getApp().UniRequest("/timeoff/authority/rejectInvited?xlsId=" + that.memberData.xlsId, "POST", "",
					           	that.header);
					           	// console.log('拒绝',res)
					           	if (res.code === 20000) {
					           		uni.showToast({
					           		    title: '已拒绝',
					           			icon: 'success',
					           		    duration: 2000
					           		});
									setTimeout(() => {
										uni.navigateBack({
										    delta: 1
										});
									},600)
					           	} else {
					           		uni.showToast({
					           		    title: '请稍后重试',
					           			icon: 'success',
					           		    duration: 2000
					           		});
					           	}
					        } else if (res.cancel) {
					            console.log('用户点击取消');
					        }
					    }
					});
				}

				

			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		background-color: #f8f8f8;
		position: relative;
		height: 100%;
		padding: 150rpx 30rpx 0rpx 30rpx;
		button {
			background-color: #fff;
			border: 0rpx;
			padding-right: 10rpx;
			padding-left: 10rpx;
			
		}
		u-popup {
			width: 40rpx;
			height: 40rpx;
			background-color: pink;
		}
		.box {
			width: 90%;
			height: 70%;
			margin: 0 auto;
			// margin-top: 100rpx;
			// background-color: pink;
			padding-top: 50rpx;
			padding: 30rpx 20rpx 20rpx 20rpx;
			letter-spacing: 2rpx;
			// margin: 0 auto;
			.title {
				height: 18%;
				display: flex;
				// justify-content: center;
				align-items: center;
				// background-color: #fff;
				font-size: 32rpx;
				
				.icon-a-ziyuan103 {
					font-size: 50rpx;
					color: #23b8ff;
				}
			}
			.excel_box {
				width: 100%;
				// margin-top: 40rpx;
				font-size: 34rpx;
				line-height: 54rpx;
				letter-spacing: 4rpx;
				// margin-bottom: 50rpx;
				font-size: 500;
			}
			button {
				width: 60%;
				margin-top: 30rpx;
			}

		}
	}
</style>
